home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / SDKs / Word Services SDK 1.0.6 / Writeswell Jr 1.2.1 Sources ƒ / Library Source / MyFolders.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-11  |  2.4 KB  |  94 lines  |  [TEXT/MMCC]

  1. /* MyFolders.c
  2.  * Deal with finding and creating folders
  3.  * ©1992 Working Software, Inc.
  4.  * This source code is copyrighted.  Permission is granted to use the Word Services
  5.  * portion of the Writeswell Jr. source code in your own programs, but you 
  6.  * may not distribute the Writeswell Jr. word-processor code as a 
  7.  * commercial product.  If you modify the code, please do not call it 
  8.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  9.  * program and don’t have to deal with a number of different versions with 
  10.  * who-knows-what going on in the code.
  11.  * 
  12.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  13.  * 17 Feb 91 Mike Crawford
  14.  */
  15. #include "MyFolders.h"
  16.  
  17. OSErr GetSysVolID( short *sysVolRefNumPtr, long *blessedIDPtr )
  18. {
  19.     WDPBRec wPB;
  20.     SysEnvRec envRec;
  21.     OSErr result;
  22.     Str31 name;
  23.  
  24.     if ( result = SysEnvirons( curSysEnvVers, &envRec ) ){
  25.         return result;
  26.     }
  27.  
  28. /*    
  29.     ClearBlock( (char*)&wPB, (short)sizeof( wPB ) );
  30. */
  31.     wPB.ioNamePtr = name;
  32.     wPB.ioVRefNum = envRec.sysVRefNum;    
  33.     wPB.ioWDIndex = 0;
  34.     wPB.ioWDProcID = '\0\0\0\0';
  35.     wPB.ioWDVRefNum = 0;
  36.     
  37.     result = PBGetWDInfo( &wPB, false );
  38.     
  39.     if ( result ){
  40.         return result;
  41.     }
  42.     
  43.     *sysVolRefNumPtr = wPB.ioWDVRefNum;
  44.     *blessedIDPtr = wPB.ioWDDirID;
  45.     
  46.     return noErr;
  47.  
  48. }/* GetSysVolID */
  49.  
  50. OSErr MakeFolder( long *idPtr, short volRefNum, long parentID, StringPtr name )
  51. {
  52.     HParamBlockRec fPB;
  53.     OSErr result;
  54.     
  55.     fPB.fileParam.ioCompletion = (IOCompletionUPP)NULL;
  56.     fPB.fileParam.ioNamePtr = name;
  57.     fPB.fileParam.ioVRefNum = volRefNum;
  58.     fPB.fileParam.ioDirID = parentID;
  59.     
  60.     result = PBDirCreate( &fPB, false );
  61.     
  62.     if ( result ){
  63.         return result;
  64.     }
  65.     
  66.     *idPtr = fPB.fileParam.ioDirID;    /* This is the dirID of the newly created folder */
  67.  
  68.     return noErr;
  69. }/* MakeFolder */
  70.  
  71. /* The following is adapted from Richard Reich's "findDirectory" function */
  72.  
  73. OSErr FindDirectory(short volNum, long parentDirID, StringPtr name, long *dirID)
  74. {
  75.     CInfoPBRec pb;
  76.     register OSErr err;
  77.  
  78. /*
  79.     ClearBlock( (char*)&pb, (short)sizeof( pb ) );
  80. */
  81.  
  82.     pb.dirInfo.ioFDirIndex = 0;            /* Look up by name and parent vRefNum */
  83.     pb.dirInfo.ioNamePtr = name;
  84.     pb.dirInfo.ioVRefNum = volNum;
  85.     pb.dirInfo.ioDrDirID = parentDirID;
  86.     err = PBGetCatInfo(&pb, FALSE);
  87.     if (err != noErr && err != fnfErr)
  88.         return (err);
  89.     if (err == fnfErr || (pb.dirInfo.ioFlAttrib & ioDirMask) == 0)
  90.         return (dirNFErr);
  91.     *dirID = pb.dirInfo.ioDrDirID;
  92.     return (err);
  93. }/* FindDirectory */
  94.